﻿//禁止全屏滑动
//document.addEventListener('touchmove', function (e) {
//	e.stopPropagation();
//	e.preventDefault();
//})
var wrongItem;
Zepto(function ($) {
	FastClick.attach(document.body);
	$("#quiz dd").click(function (e) {
		e.preventDefault();
		$(this).addClass("active");
		$(this).siblings("dd").removeClass("active");
	});
	$("#submit a").click(function (e) {
		e.preventDefault();
		checkAnswer();
	});
	$(".wrong-notice img").click(function (e) {
		e.preventDefault();
		$(".wrong-notice").hide();
		location.href = "#" + wrongItem;
	});
});

function checkAnswer() {
	var wrongCount = 0, blankCount = 0;
	$("#quiz dl").each(function (index, element) {
		var correctA = $(this).data("answer");
		var correctItem = $(this).children("dd").eq(correctA - 1);
		$(this).children("dd").removeClass("wrong correct");
		if ($(this).children("dd.active").length < 1) {
			blankCount++;
		}
		if (correctItem.hasClass("active")) {
			correctItem.addClass("correct");
		}
		else {
			$(this).children("dd.active").addClass("wrong");
			wrongCount++;
		}
	});
	if (blankCount > 0) {
		alert("您还未答完题！");
		return false;
	}
	if (wrongCount < 1) { location.href = "/qa/result"; }
	else {
		$(".wrong-notice").show();
		wrongItem = $("#quiz dd.wrong").parent().eq(0).attr("id");
	}
}
